home *** CD-ROM | disk | FTP | other *** search
- EGT Viewer V6.1 Copyright 1996 by Beowulf Shaeffer
- B2E Conversionprogram V4.0 Copyright by Beowulf Shaeffer
- ========================================================
- Member of The Powerdrome's Beta Zone
-
- THE PURPOSE OF THIS FILE
- ------------------------
- This file, I hope, can be used as a tutorial on building software. I mean all
- the steps, from the problem to the solution. Naturally is this just one case,
- and not all problems are easy to solve. The 'problem' I refer to, is in this
- case, 'to display a picture, quickly and with very little code'. The solution
- however, consists not only of the source of the progam(s), but the reasoning
- in this tutorial contributes to it heavily also. Understanding and imagining
- the steps one by one will make you a better programmer also. (Not that I'm
- making millions while programming :-) Short sentences should help you, under-
- standing the what the how and the why. Topics will be handled, as they come
- up.
-
- DISCLAIMER
- ----------
- I hate this sort of things, anyway:
- IF YOU DECIDE TO USE IT, IT'S YOUR RESPONSIBILITY, NOT MINE!
- USE AT YOUR OWN RISK. YES IT'S PUBLIC-DOMAIN, EXEPT FOR EV.COM AND
- B2E.EXE, THOSE ARE FREEWARE.
- This file was created as a tutorial for the X2 contest 1995 (great guys!).
-
- THE PROBLEM
- -----------
- When I make programs, mostly in BASIC, I also want to make the program
- attractive by showing some intro's or other pictures. Using the PSET statement
- a whole lot of code-lines must be used to make a logo of some sort. All that
- code, I like to call that 'overhead', is a waste of memory. Then it struck me!
- Make a picture, or logo in this case, with a paint-program, and just display
- it using a short (ASM) routine.
-
- POSSIBILITIES
- -------------
- Make a picture with a paint-program. View it with a viewer for the used,
- format and grab the video-memory with a picture-grabber.
- GRABBERS:
- A grabber takes a look at your screen, and transfers all colors and
- text and graphics to file(s). Mostly a grabber makes a palette-, and
- a datablockfile. (PAL and BLD files)
- The BLD file can be loaded using the BASIC BLOAD statement. The PAL (palette) file however, is more tricky! I tried to
- load the palette (ANY palette) into the PALETTE USING statement, using the
- right procedures of putting it in an array first.
- PALETTE:
- A palette, is a set of values, that represent the RED, GREEN and BLUE
- levels in each of the 256 colors. So 256 colors times 3 (R, G and B)
- is 768 bytes.
- This program still was big AND slow. The loading of the picture wasn't the
- problem here, but the palette-loading took a second or two. Too long for 768
- bytes, I think... Instead of loading the two files, it would be better to load
- only one file. A BMP file had the right format I think!
- BMP FORMAT:
- The file starts with a header of 54 bytes. They are of no use to us.
- Then, a block of 1024 (!) bytes represents the palette for the
- picture. Yes, every color has 4 bytes instead of 3. (R, G, B and 0)
- Every value for the colorcomponents, lies between 0 and 255. After the
- last palettebyte, the actual picture comes. In our case 320x200 bytes
- or 64000. A typical 320x200x256 BMPfile is 65078 bytes large. There
- ARE compressed BMPfiles, but they are of no use for us.
- These BMP's are UNCOMPRESSED, so I didn't have to worry about decompressing,
- what would take extra time to do. Taking care of the loading of the palette,
- wasn't that big of a challenge, however programming the colorvalues in BASIC,
- requires values from 0 to 63, so devision by 4 was a must! Reading line for
- line, and BLOADING the rest of the BMPfile, I suddenly became aware, that BMP
- files are written UPSIDE-DOWN! The conversion from 4 to 3 bytes per color, and
- the devision of the values made the whole program slower. Making the program
- writing the picture from down to up, decreased the speed also. I had to come
- up with a better solution.
-
- THE BETTER SOLUTION
- -------------------
- My interest in assembly-coding increases everytime something has to be small
- and quick. So I decided to do 'it' in assembler! I have a great book, that
- came with my MS-DOS 3.21, called 'PROGRAMMER'S REFERENCE'. Reading it is a
- great help for gaining ideas for problem-solving. There are DOS- and BIOS-
- functions, described in detail.
- DOS AND BIOS FUNCTIONS
- A basic I/O system (BIOS) provides 'simple' access to hardware in the
- computer. The disk operating system (DOS) provides us with the more
- advanced functions. When a function is needed, some registers must
- have specific values, so the routines know what operations to do. More
- about this in the ASM file.
- Some functions, I decided to go along with, just HAD to be used. For instance
- the LOAD PALETTE BLOCK function, sounded great! And READ BLOCK FROM DISK is
- another interesting one!
-
- COMPATTIBILITY
- --------------
- All people of the world should be able to view the pictures made by me, so I
- went along with the 320x200x256 mode, or mode 13h. All computers with ANY kind
- of VGA adapter can view in mode 13h. The only thing I had to do, was to check
- if a VGA card is present. No VGA means no display!
-
- CONVERSION
- ----------
- Now another point: The smaller the file is, the quicker it's in memory!
- There are 1024 bytes as a palette in a BMP file. Every fourth byte can be left
- out of the palette, so the complete palette should take 768 bytes. Ofcause we
- lose the header. We just reduced the file with 310 bytes. The function that
- loads a palette block in assembler, uses an other order of colors. B and R
- must be swapped. AND ofcause the picture must be put upside-down. When the
- picture is right-side-up, only ONE functioncall loads the entire picture!
- To do the conversion I built myself a convertor called B2E, or BMP to EGT.
- Well I had to give it a name, so I took EGT (local humor) as an extention.
- The source is in QB45 basic, and a lot of remarks should make it clearer for
- you to understand the process of conversion. The trick here is, to load the
- BMP file slowly and from bottom to top. After that, all colors are loaded and
- converted. This complete process is kind of slow, and the output EGT file, is
- written. The inputfile (BMP) is checked for it's size, to determine the
- format. Now, the conversion takes a lot of time, but the loading of the EGT
- file by the viewer-routine will be fast as lightning!
-
- USING B2E
- ---------
- Type B2E filename (without extention)
- When the file is found, the picture will be drawn form bottom to top
- but in a default palette. Calculating the new palette, you will see
- the picture getting more and more it's own colors. When the colors are
- complete, the led on the drive should be blinking. When the writing is
- done, the screen returns to the normal screenmode.
-
- USED PROGRAMMING SOFTWARE
- -------------------------
- Any ASCII editor, such as EDIT.COM (MS-DOS 5.0+)
- Any assembler, such as MASM, TASM or WASM (WASM is shareware, perfect!)
- QBASIC or QB
-
- UPDATE #1
- ---------
- Along the way and improving the viewer, there came up some ideas, which were
- implemented with very little effort. It is possible to chain multiple EGT
- files using:
-
- COPY /B PICTURE1.EGT+PICTURE2.EGT+PICTURE3.EGT GROUP.EGT
-
- So, multiple pictures can be packed into ONE single file! Nice huh? The last
- update provided browsing functions to the viewer. You can view the [HOME]
- picture (first one), the [END] picture (last one), and using left and right
- cursor keys to view the previous and next picture.
-
- FUNNY
- -----
- I stretched the machine-code to 512 bytes, so that the program will take up
- exactly 1 cluster of a (floppy-) disk.
-
- PROGRAMMING IN ASSEMBLER
- ------------------------
- The why, and the order of the assembly-listing is described in the EV.ASM
- file. So I won't get into it here too much. Fighting segment-adresses, I had
- to use a debugger. The debugger I used, is called AFD, or Advanced Fullscreen
- Debug. The MS-DOS's DEBUG will do also... Borland's TASM, which I bought
- recently, is a little fuzzy to me right now, so I used WASM in this case
- instead. The syntax, used to create EV.ASM is NOT recognisable by TASM or
- MASM. You have to alter it to your own assembler. Another disadvantage of TASM
- in this case is, the object linking and the exe to bin conversion is a little
- too much work. WASM converts an ASM directly to the COM version.
-
- EV PRACTICAL
- ------------
- EGT Viewer, in the practical house of terms, is very #$$@$# FAST! The display-
- speed is as fast as the drive with the EGT file. It's NOT possible to make a
- faster viewer! (Hey, this software runs on a XT also!) The picture is loaded
- using only two function-commands! Above, I mentioned a way to make multiple-
- picture-EGT files. The displaying of this groupfile must be done with:
-
- "EV GROUP".
-
- By the way, up to 22 EGT pictures can be put into one on a HD 3.5" floppy! The
- EV.COM can be put on it also! If the pictures were archived, up to 32 pictures
- would fit on a 1.44 floppy. Viewing the groupfile, and the last picture of the
- file is on your screen, pressing right- or up-arrow will result in an exit.
- That means that the screen is switched back to textmode, and you're back in
- DOS (or Windows). Pressing ESC at ANY point of viewing will also return your
- PC to textmode/DOS or Windows.
-
- THE PURPOSE OF THE VIEWER
- -------------------------
- It turned out to be a great way for making small introductions etcetera.
- However, I first wanted to make a picture-loader (viewer) to build into my
- BASIC programs, so the problem was solved.
- BUILDING IT IN
- Using the QB45 quick library QB.LQB, it's possible to do a CALL
- ABSOLUTE to a string with the machine-code.
- Also the quick loading of pictures, can be used in games.
-
- UPDATE #2
- ---------
- I just bought myself a copy of Windows'95. The funny thing about that, and
- other versions of Windows, are the ASSOCIATE routines. These little buggers
- open the viewer files by INCLUDING the .EGT extention to the file! I'm very
- new at the '95 thing, and there MAY be a solution to it, but I decided to make
- a little modification to the viewer. Now you may or may not use the .EGT
- extention on the commandline. The .ASM source is updated, so the how will be
- explained also. I justified the text in this .DOC a little bit for nicer
- printing.
-
- THANX
- -----
- This little tutorial got me the second price in the '95 contest. I'd like to
- thank everyone who made that possible.
-
- EPILOG
- ------
- I hope you learned something about the thoughts involving programming. Maybe
- in the future, it's recommendable to switch the file's extentions from EGT to
- X2P (X2 Picture:-). You may use the sources for your own purposes, but the
- EV.COM and B2E.EXE may NOT be altered. Any programs made using my sources MUST
- have other names! Let me know, if you like the routines...
-
- E-mail me : beowulf@iaehv.nl (if I still have my account there then)
- Fidonet : 2:292/114.8
-
- Greetings from Beowulf Shaeffer (Dolf Spoor)
- Geldrop, The Netherlands
-
-